package main.string;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenggm
 * @create 2017-02-13 17:53
 **/
public class CreateCode  {
	public String  generateCode(String newCode) throws Exception{
		if(null == newCode){
			throw new Exception("code不存在");
		}
		//code长度已经定好为4的倍数
		if(4==newCode.length()){
			newCode = (new Integer(newCode)+1)+"";
		}
		if(newCode.length()/4>1){
			String str2 = newCode.substring(newCode.length()-4,newCode.length());
			String str1 = newCode.substring(0,newCode.length()-4);
			newCode = str1+(new Integer(str2)+1)+"";
		}
		return newCode;
	}

	public String getCode() throws Exception{
		String temp = null;
		for(int i =0 ;i <0;i++){
			temp = temp+"0000";
		}
		return temp;
	}
	@Test public void test() throws Exception {
		List<String> list = new ArrayList<String>();
//		String code = null;
		String code1 = "1200";
		String code2 = "12001250";
		String code3 = "120012053206";
		String code4 = "1200012000000001";
//		list.add(code);
		list.add(code1);
		list.add(code2);
		list.add(code3);
		list.add(code4);

		for (String co : list) {
		    String newCode = generateCode(co);
		    System.out.println(newCode);
		}
	}

	@Test public void test2() throws Exception {
		String code = getCode();
		System.out.println(code);
	}

	@Test public void test3() throws Exception {
		String newCode = "1200012000000001";
		String str2 = newCode.substring(newCode.length()-4,newCode.length());
		String str1 = newCode.substring(0,newCode.length()-4);
		newCode = str1+(new Integer(str2)+1)+"";
		System.out.println(newCode);
	}

	@Test public void test4() throws Exception {
		String newCode = "1200012000000001";
		String code = newCode.substring(4*(new Integer(2)),4*new Integer(3));
		System.out.println("1---------"+code);
		if("0000".equals(code)){
			newCode =  newCode.substring(0,4*(3-1));
			System.out.println("2---------"+newCode);
		}
	}

	@Test public void test5() throws Exception {
		String code = "00120025";
//		code = code.substring(0,code.length()-4)+"00000001";
		code = code.substring(0,4);
		System.out.println("3---------"+code);

	}

}
